<?php
error_reporting(0);
if(!defined('IN_DISCUZ') || !defined('IN_ADMINCP')){
	exit('Access Denied');
}
if(!defined('Adz_class')){include('Adz.class.php');}
$tablename = 'plugin_weixin';
$op = isset($_GET['op']) ? $_GET['op'] : 'view';
if($op == 'del'){
	include template('common/header_ajax');
	$bindid = rtrim($_POST['bindid'], ',');
	$uidarr = explode(',', $bindid);
	$newid = implode(',',$uidarr);
	if($newid) DB::delete($tablename, ' uid in ('.addslashes($newid).')');
	echo $newid;
	include template('common/footer_ajax');
} elseif ($op == 'view'){
	$page = isset($_GET['page']) ? $_GET['page'] : '1';
	$perpage = 10;
	//total
	$sql = 'SELECT COUNT(uid) as num FROM '.DB::table($tablename);
	$result = DB::fetch_first($sql);
	$total = $result['num'];
	$sql = 'SELECT a.*,b.username FROM '.DB::table($tablename).' a left join '.DB::table('common_member').' b on a.uid=b.uid limit '.($page-1)*$perpage.','.$perpage;
	$rs = Adz::fetch_all($sql);
	foreach ($rs as $k => $v) {
		$profile = json_decode($v['profile']);
		$v['weixin_username'] = $profile->username;
		$v['weixin_nickname'] = $profile->nickname;
		$lists[] = $v;
	}
	$pagestr = multi($total, $perpage, $page, 'admin.php?action=plugins&operation=config&identifier=acan_weixin&pmod=manage');
	showtableheader(lang('plugin/acan_weixin', 'bindedusers'));
	$lang_del = lang('plugin/acan_weixin', 'delete');
	showsubtitle(array(
		'',
		lang('plugin/acan_weixin', 'forumuserid'),
		lang('plugin/acan_weixin', 'forumusername'),
		lang('plugin/acan_weixin', 'weixinuid'),
		lang('plugin/acan_weixin', 'weixinusername'),
		lang('plugin/acan_weixin', 'weixinnickname'),
		$lang_del,
	));
	include template('acan_weixin:manage');
}
?>